package com.kaluli.project.repository.impl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.kaluli.project.domain.entity.KllOrderDataVo;
import com.kaluli.project.domain.entity.KllUserDataVo;
import com.kaluli.project.domain.repository.KllDataRepository;
import com.kaluli.system.repository.AbstractRepositorySupport;

@Repository
public class KllDataRepositoryImpl extends AbstractRepositorySupport<KllUserDataVo> implements KllDataRepository{

	@Override
	protected Class<KllUserDataVo> getEntityClass() {
		// TODO Auto-generated method stub
		return KllUserDataVo.class;
	}

	
	@Override
	public List<KllUserDataVo> findByTime(String dateTime) {
		StringBuffer sql = new StringBuffer("SELECT `user_id` as id,`user_name` ,FROM_UNIXTIME(u.`ct_time`) AS ct_time,a.`name` , a.`region` , a.`street`   , a.`mobile`,a.`postcode` ,a.`identity_number`");
		sql.append(" FROM `kll_user` u LEFT JOIN `trd_user_delivery_address` a ON u.`user_id` =a.`hupu_uid` ");
		sql.append("  WHERE FROM_UNIXTIME(u.`ct_time`) >='"+dateTime+"'  ");
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		String today = sf.format(new Date());
		sql.append(" and FROM_UNIXTIME(u.`ct_time`) <'"+today+"' ");
		List<KllUserDataVo> list = excuteSql(sql.toString());
		if(list != null && list.size()>0){
			if(list.get(0) == null){
				return null;
			}
		}
		return list;
	}
	
	
	

}
